<?php
include_once('../../app/connection.php');

if(isset($_POST['action']))
{
    $action = $_POST['action'];
    
    if($action == "get_tenmh")
    {
        if(isset($_POST['mamh']))
        {
            $mamh = $_POST['mamh'];
            $sql = "SELECT * FROM monhoc WHERE MAMONHOC='".$mamh."' AND TRANGTHAI = 1";
            $result = mysql_query($sql);
            if (mysql_num_rows($result)!= 0) {
                $row = mysql_fetch_assoc($result);
                echo $row['TENMONHOC'];
            }
        }
    }
    
    if($action == "get_tengv")
    {
        if(isset($_POST['magv']))
        {
            $magv = $_POST['magv'];
            $sql = "SELECT * FROM giaovien WHERE MAGIAOVIEN='".$magv."' AND TRANGTHAI = 1";
            $result = mysql_query($sql);
            if (mysql_num_rows($result)!= 0) {
                $row = mysql_fetch_assoc($result);
                echo $row['HOTEN'];
            }
        }
    }
    
    if($action == "add_lop")
    {
            $mamh = $_POST['mamh'];
            $malop_mh = $_POST['malop_mh'];
            $maloai = $_POST['maloai'];
            $magv = $_POST['magv'];
            $thu = $_POST['thu'];
            $ca = $_POST['ca'];
            $phong = $_POST['phong'];
            $toida = $_POST['toida'];
            $nam = $_POST['nam'];
            $hocky = $_POST['hocky'];
            
            $sql = "INSERT INTO `lop`(MAMONHOC, MALOP, MAGIAOVIEN, MALOAI, NAM, HOCKY, THU, CA, PHONG, TOIDA, TRANGTHAI) VALUES 
                    ('$mamh','$malop_mh','$magv','$maloai','$nam','$hocky','$thu','$ca', '$phong', '$toida', 1)";
            $result = mysql_query($sql) or die(mysql_error());
            
            echo "Đã thêm ". $mamh.".".$malop_mh." vào HK ".$hocky." năm ".$nam;
    }
}

?>